# Define the compiler options
CC	  = g++
CXX	  = g++
CXXFLAGS  = -pipe -O2 -Wall -W -ansi -pedantic-errors
CXXFLAGS += -Wmissing-braces -Wparentheses -Wold-style-cast

# Paths
SRC	= src
SERVER 	= $(SRC)/server
CLIENT 	= $(SRC)/client

# Define what to do when make is executed without arguments.
PROG 	= bin/nuseserver_inmem bin/nuseclient bin/nuseserver_indisk
SERVERO1	= $(SERVER)/nuseserver.o $(SERVER)/server.o $(SERVER)/database1.o
SERVERO2	= $(SERVER)/nuseserver.o $(SERVER)/server.o $(SERVER)/database2.o
CLIENTO	= $(CLIENT)/main.o $(CLIENT)/core.o $(CLIENT)/gui.o
OBJS 	= $(SERVERO1) $(SERVERO2) $(CLIENTO) $(SRC)/connection.o  

.PHONY: all
all: $(PROG)

.PHONY: clean
clean:
	$(RM) $(OBJS)

.PHONY: cleanall
cleanall: clean
	$(RM) $(PROG)

.PHONY: inmem
inmem: bin/nuseserver_inmem

.PHONY: indisk
indisk: bin/nuseserver_indisk

# Define rules for object files.
$(SERVER)/database1.o: $(SERVER)/database.cc
	$(CXX) $(CXXFLAGS) -c -o $(SERVER)/database1.o $^
$(SERVER)/database2.o: $(SERVER)/database.cc
	$(CXX) -DIN_DISK $(CXXFLAGS) -c -o $(SERVER)/database2.o $^

# Rules for programs.
bin/nuseserver_inmem: $(SERVERO1) $(SRC)/connection.o 
	$(CXX) -o bin/nuseserver_inmem $^
bin/nuseserver_indisk: $(SERVERO2) $(SRC)/connection.o
	$(CXX) -o bin/nuseserver_indisk $^

bin/nuseclient: $(CLIENTO) $(SRC)/connection.o
	$(CXX) -o bin/nuseclient $^
